package com.test.java;

import java.util.Scanner;

/**
 * 锤子剪刀布:现给出两人的交锋记录，请统计双方的胜、平、负次数，并且给出双方分别出什么手势的胜算最大。
 * =============================================================
 * Version          Author          Date            Description
 * 1.0              白建         2017/12/18             创建
 * =============================================================
 */
public class Java_9
{

    private static int win, lose, equal, all;

    private static int A_C, A_J, A_B, B_C, B_J, B_B;

    public static void main(String[] args)
    {

        init();
        process();
    }

    private static void init()
    {

        Scanner scanner = new Scanner(System.in);
        all = scanner.nextInt();
        scanner.nextLine();

        for (int i = 0; i < all; i++)
        {
            String[] strings = scanner.nextLine().split(" ");
            switch (winOrLose(strings[0], strings[1]))
            {
            case 1:
                win++;
                count(1, strings[0]);
                break;
            case 0:
                equal++;
                break;
            case -1:
                lose++;
                count(-1, strings[1]);
                break;
            default:
                break;
            }
        }
    }

    private static int winOrLose(String a, String b)
    {

        if (a.equalsIgnoreCase(b))
        {
            return 0;
        }
        if ((a.charAt(0) == 'C' && b.charAt(0) == 'J') || (a.charAt(0) == 'J' && b.charAt(0) == 'B') || (
                a.charAt(0) == 'B' && b.charAt(0) == 'C'))
        {
            return 1;
        }
        else
        {
            return -1;
        }
    }

    private static void count(int flag, String gesture)
    {

        if (flag == 1)
        {
            switch (gesture)
            {
            case "C":
                A_C++;
                break;
            case "J":
                A_J++;
                break;
            case "B":
                A_B++;
                break;
            default:
                break;
            }
        }
        else if (flag == -1)
        {
            switch (gesture)
            {
            case "C":
                B_C++;
                break;
            case "J":
                B_J++;
                break;
            case "B":
                B_B++;
                break;
            default:
                break;
            }
        }
    }

    private static void process()
    {

        System.out.print(win + " " + equal + " " + lose + "\n");
        System.out.print(lose + " " + equal + " " + win + "\n");
        if (A_B >= A_C)
        {
            if (A_B >= A_J)
            {
                System.out.print("B");
            }
            else
            {
                System.out.print("J");
            }
        }
        else
        {
            if (A_C >= A_J)
            {
                System.out.print("C");
            }
            else
            {
                System.out.print("J");
            }
        }
        System.out.print(" ");
        if (B_B >= B_C)
        {
            if (B_B >= B_J)
            {
                System.out.print("B");
            }
            else
            {
                System.out.print("J");
            }
        }
        else
        {
            if (B_C >= B_J)
            {
                System.out.print("C");
            }
            else
            {
                System.out.print("J");
            }
        }
    }
}
